package com.twu.biblioteca.library.shelf;

import com.twu.biblioteca.control.Strings;
import com.twu.biblioteca.library.item.Book;
import com.twu.biblioteca.library.item.LibraryItem;
import java.util.TreeSet;

public class BookShelf extends Shelf {

    public BookShelf() {
        collection = new TreeSet<LibraryItem>();
        collection.add(new Book(1, "Book1", "Author1"));
        collection.add(new Book(2, "Book2", "Author2"));
        collection.add(new Book(3, "Book3", "Author3"));
    }

    public boolean checkoutItem(int id, String libraryNumber) {
        Book book = (Book)findItem(id);
        if( (book != null) && book.getAvailability() ){
            collection.remove(book);
            book.checkoutBook(libraryNumber);
            collection.add(book);
            System.out.println(Strings.bookCheckoutEnjoy);
            return true;
        }
        System.out.println(Strings.bookCheckoutSorry);
        return false;
    }

    public boolean returnItem(int id) {
        Book book = (Book)findItem(id);
        if( (book != null) && !book.getAvailability() ) {
            collection.remove(book);
            book.returnBook();
            collection.add(book);
            System.out.println(Strings.bookReturnThanks);
            return true;
        }
        System.out.println(Strings.bookReturnSorry);
        return false;
    }

}
